package com.example.controller;

import com.example.config.NoWrapResponseAdvice;
import com.example.constant.Constant;
import com.example.entity.UserPO;
import com.example.entity.UserVO;
import com.example.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/userInfo")
public class UserInfoController {

    @Resource
    private UserService userService;

    @PostMapping("/getUserInfos1")
    public List<UserVO> getUserInfos1(@Valid @RequestBody UserVO user) {
        log.info("{}",user);
        String camp = user.getCamp();
        List<UserVO> list = Constant.USER_INFO_LIST;
        return list.stream().filter(s->s.getCamp().equals(camp)).collect(Collectors.toList());
    }

    @GetMapping("/getUserInfos2")
    @NoWrapResponseAdvice
    public List<UserVO> getUserInfos2(@Validated @RequestBody UserVO user) {
        log.info("{}",user);
        return Constant.USER_INFO_LIST;
    }

    @PostMapping("/getById")
    public UserPO get(@RequestBody UserPO req) {
        return userService.getById(req.getId());
    }
    @PostMapping("/get1ById")
    public UserPO get1ById(@RequestBody UserPO req) {
        return userService.get1ById(req.getId());
    }
    @PostMapping("/get2ById")
    public UserPO get2ById(@RequestBody UserPO req) {
        return userService.get2ById(req.getId());
    }

    @PostMapping("/getAll")
    public List<UserPO> getAll() {
        return userService.list();
    }

    @PostMapping("/addUser")
    public String addUser() {
        return userService.addUser();
    }
}